<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body style="height:3000px">
  <div id="app">
    <button @click="changeState">{{isShow?'隐藏':'显示'}}</button>
    <keep-alive>
      <home v-if="isShow"></home>
    </keep-alive>
  </div>
  <template id="tpl">
    <div>
      <h1>我是home页</h1>
      <input type="text" v-model="msg">
    </div>
  </template>
  <script src="./vue.js"></script>
  <script>
   
    const Home = {
      template:"#tpl",
      data(){
        return {
         msg:""
        }
      },
      methods:{
        
      },
      beforeCreate(){
        console.log('beforeCreate')
      },
      created(){
        console.log("created")
      },
      beforeMount(){
        console.log('beforeMount')
       
      },
      mounted(){
        console.log('mounted')
       
      },
      beforeUpdate(){
        console.log('beforeUpdate')
        
      },
      updated(){
        console.log('updated')
       
      },
      beforeDestroy(){
        console.log('组件卸载之前');
      
      },
      destroyed(){
        console.log("组件已经卸载")
      },
      activated(){
        console.log("组件再一次被激活的时候调用")
        // 被keep-alive 缓存组件 在 再一次被激活（显示出来）时触发,在这里做 缓存组件 数据 局部刷新
      },
      deactivated(){
        console.log('组件再一次隐藏了')
        // 被 keep-alive 缓存组件 在再一次隐藏时触发，可以在这里 清除定时器、注销全局事件
      }
    }
    
    Vue.component('Home',Home)
    const vm = new Vue({
      el:"#app",
      data:{
        isShow:true
      },
      methods:{
        changeState(){
          this.isShow = !this.isShow
        }
      }
    })
  </script>
</body>
</html>
